package com.wn.controller;

import com.github.pagehelper.PageInfo;
import com.wn.annotation.RequireRoles;
import com.wn.entity.Hotelinfo;
import com.wn.entity.Travelinfo;
import com.wn.service.TravelinfoService;
import com.wn.utils.PageParam;
import com.wn.utils.Rsp;
import com.wn.utils.SystemControllerLog;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.UUID;

/**
 * (Travelinfo)表控制层
 *
 * @author makejava
 * @since 2020-10-26 09:41:20
 */
@RestController
@RequestMapping("travelinfo")
public class TravelinfoController {
    /**
     * 服务对象
     */
    @Resource
    private TravelinfoService travelinfoService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("getTravelById")
    @RequireRoles(roles = {"super"})
    @ApiOperation("查询单条数据")
    public Rsp getTravelById(String id) {
            return Rsp.success(travelinfoService.queryById(id));
    }


    /**
     *分页查询数据
     *
     * @return 单条数据
     */
    @SystemControllerLog(description = "分页查询出行信息")
    @PostMapping("searchSomeTravelByPage")
    @RequireRoles(roles = {"admin","super_admin","reception","guide"},index = 1)
    @ApiOperation("查询所有 支持 多条件 分页 排序 查询")
    public Rsp searchSomeTravelByPage(@RequestBody  PageParam<Travelinfo> pageParam,
                                      @RequestHeader("token") String token){
            return Rsp.success(travelinfoService.queryAllByLimit(pageParam));
    }
    /**
     *增加单个数据
     *
     * @param travel 出行信息
     * @return 单条数据
     */
    @SystemControllerLog(description = "增加出行信息")
    @PostMapping("addOneTravel")
    @ApiOperation("增加数据")
    @RequireRoles(roles = {"super_admin"},index = 1)
    public Rsp addOneTravel(@RequestBody @Valid Travelinfo travel,
                            @RequestHeader("token") String token){


            return Rsp.success(travelinfoService.insert(travel));

    }

    /**
     *修改单个数据
     *
     * @param travel 出行信息
     * @return 单条数据
     */
    @SystemControllerLog(description = "修改出行信息")
    @PostMapping("updateTravel")
    @ApiOperation("修改单条数据")
    @RequireRoles(roles = {"super_admin","admin"},index = 1)
    public Rsp updateTravel(@RequestBody @Valid Travelinfo travel,
                            @RequestHeader("token") String token){
            return Rsp.success(travelinfoService.update(travel));

    }

    /**
     *逻辑删除单个数据
     *
     * @return 单条数据
     */
    @SystemControllerLog(description = "逻辑删除出行信息")
    @PostMapping("deleteTravelLogical")
    @ApiOperation("逻辑删除单条数据")
    @RequireRoles(roles = {"super_admin"},index = 1)
    public Rsp deleteTravelLogical(@RequestBody Travelinfo travel,
                                   @RequestHeader("token") String token){

            return Rsp.success(travelinfoService.deleteLogical(travel.getId()));

    }

}
